<template>
	<view class="container" :style="{ height: wanlsys.windowHeight + 'px' }">
		<view class="tip">
			<view class="bg-img auth-safe" :style="{ backgroundImage: `url(${'/static/images/face/auth-safe.png'})` }"></view>
			<text>以下信息仅用于实名认证</text>
		</view>

		<view class="main">
			<view class="header">
				<image class="auth-face" v-if="!result" :src="'/static/images/face/auth-face.png'" mode="widthFix"></image>
				<image class="auth-success" v-if="result == 'success'" :src="'/static/images/face/success.png'"
					mode="widthFix"></image>
				<image class="auth-fail" v-if="result == 'fail'" :src="'/static/images/face/fail.png'" mode="widthFix"></image>

				<text v-if="!result">预约申请领养宠物需要人脸识别认证</text>
				<view v-else class="result-text">
					<text class="title" v-if="result == 'success'">人脸认证成功</text>
					<text class="title" v-if="result == 'fail'">人脸认证失败</text>
					<text class="desc">人脸验证-填写领养信息-审核-领养成功</text>
				</view>
			</view>

			<!-- 人脸识别 - 输入身份信息 -->
			<view class="userinfo" v-if="!result">
				<view class="userinfo-head">
					<view class="title">身份认证</view>
					<text class="desc">请如实填写身份信息, 否则无法通过人脸验证</text>
				</view>
				<view class="cu-form-group">
					<view class="title">姓名</view>
					<input type="text" placeholder="请输入姓名" v-model="userInfo.name"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">身份证</view>
					<input type="text" placeholder="请输入身份证号" v-model="userInfo.IDCode"></input>
				</view>
			</view>
		</view>


		<!-- 人脸识别 - 输入信息 -->
		<block v-if="!result">
			<view class="wanlian cu-bar tabbar foot flex flex-direction"><button @tap="auth_start"
					class="cu-btn wanl-bg-theme round lg">人脸识别</button></view>
		</block>

		<!-- 人脸识别 - 成功 -->
		<block v-if="result == 'success'">
			<view class="wanlian cu-bar tabbar foot flex flex-direction"><button @tap="auth_success"
					class="cu-btn wanl-bg-theme round lg">下一步</button></view>
		</block>

		<!-- 人脸识别 - 失败 -->
		<block v-if="result == 'fail'">
			<view class="wanlian cu-bar tabbar foot flex flex-direction"><button @tap="auth_fail"
					class="cu-btn wanl-bg-theme round lg">重新验证</button></view>
		</block>
	</view>
</template>

<script>
export default {
	data() {
		return {
			wanlsys: {},
			userInfo: {
				name: '',
				IDCode: ''
			},
			result: 'fail'
		};
	},
	onLoad(option) {
		this.wanlsys = this.$wanlshop.wanlsys();
		this.result = option.type;
	},
	methods: {
		// 开始人脸识别
		auth_start(){
			for(let item in this.userInfo){
				if(this.userInfo[item] == ''){
					this.$wanlshop.msg('请完善身份信息')
					return;
				}
			}
			
			console.log('人脸识别')
		},
		
		// 验证成功
		auth_success(){
			uni.redirectTo({
				url:`/pages/adopt/information`
			});
		},
		
		// 验证失败
		auth_fail(){
			// 重新验证人脸
			
		}
	}
}
</script>

<style scoped lang="scss">
.wanlian.cu-bar.tabbar {
	background-color: transparent;
}

.wanlian.cu-bar.tabbar .cu-btn {
	width: calc(100% - 50rpx);
}

.wanlian.cu-bar.tabbar .cu-btn.lg {
	font-size: 32rpx;
	height: 86rpx;
}

page {
	background-color: #fcfcfc;
}

.container {
	.tip {
		width: 100%;
		background: linear-gradient(to right, #ffffff -10%, #3DFF71 130%);
		display: flex;
		align-items: center;
		gap: 30rpx;
		padding: 14rpx 40rpx;
		color: #3D3D3D;
		font-size: 22rpx;
		margin-bottom: 110rpx;

		.auth-safe {
			width: 34rpx;
			height: 38rpx;
		}
	}

	.main {
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;

		.header {
			width: 100%;
			margin-bottom: 60rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: 26rpx;
			color: #3D3D3D;

			.auth-face {
				width: 50%;
				margin-bottom: 32rpx;
			}

			.auth-success {
				width: 314rpx;
				transform: translateX(-30rpx);
				margin-bottom: 76rpx;
			}

			.auth-fail{
				width: 160rpx;
				margin-bottom: 76rpx;
			}

			.result-text {
				display: flex;
				flex-direction: column;
				align-items: center;
				gap: 50rpx;

				.title {
					font-size: 40rpx;
					color: #3D3D3D;
				}

				.desc {
					color: #9C9C9C;
					font-size: 24rpx;
				}
			}
		}

		.userinfo {
			width: 100%;
			background-color: #ffffff;
			border-radius: 16rpx;
			box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.05);
			color: #3D3D3D;

			.userinfo-head {
				padding: 28rpx;

				.title {
					font-size: 28rpx;
					margin-bottom: 10rpx;
				}

				.desc {
					font-size: 22rpx;
					color: #9C9C9C;
				}
			}

			.cu-form-group {
				.title {
					font-size: 28rpx;
				}

				input {
					text-align: right;
				}
			}
		}

	}
}
</style>